#coding='utf-8'
from requests import Request, Session
import time
from imp import reload
from urllib import request as urllib2
from lxml import etree
import pymysql
import json
import sys
reload(sys)
import requests
from pyecharts import Bar,EffectScatter, Line
def get_one_page(url):
    response = requests.get(url)
    response.encoding = "utf-8"
    if response.status_code == 200:
        return response.text
    return None

def main():
    id = ['1862', '526','1628', '1690','779', '2864' ]
    player = []
    pts = []
    season = []
    james = []
    curry = []
    harden = []
    ouwen = []
    kd = []
    cp3 = []
    db = pymysql.connect(host='localhost', user='root', password='', port=3306, db='nbaData', charset='utf8')
    cursor = db.cursor()
    for i in id:
        sql = "select nbaplayer.id, nbaplayer.player,playerseasonsvg.season,playerseasonsvg.pts, playerseasonsvg.fta from nbaplayer,playerseasonsvg WHERE  nbaplayer.id = \'"+ i +"\' AND nbaplayer.id =playerseasonsvg.playerId AND playerseasonsvg.season >='11-12' "
        cursor.execute(sql)
        results = cursor.fetchall()
        for row in results:
            if row[0] == 1862:
                james.append(row[4])
                season.append(row[2])
            elif row[0] == 526:
                curry.append(row[4])
            elif row[0] == 1628:
                harden.append(row[4])
            elif row[0] == 1690:
                ouwen.append(row[4])
            elif row[0] == 779:
                kd.append(row[4])
            elif row[0] == 2864:
                cp3.append(row[4])
            # player.append(row[2])
            # pts.append(row[3])
    season.reverse()
    james.reverse()
    curry.reverse()
    print(season)
    print(james)
    print(curry)
    line = Line("生涯赛季罚球",width=1400,height=600)
    line.add("詹姆斯", season, james, is_label_show=True)
    line.add("库里", season, curry,is_label_show=True)
    line.add("欧文", season, ouwen, is_label_show=True)
    line.add("哈登", season, harden, is_label_show=True)
    line.add("杜兰特", season, kd, is_label_show=True)
    line.add("保罗", season, cp3, is_label_show=True)

    line.render()

if __name__ == '__main__':
    main()